package com.wiki.gds.base.database.generate;

import org.beetl.sql.core.*;
import org.beetl.sql.core.db.DBStyle;
import org.beetl.sql.core.db.MySqlStyle;
import org.beetl.sql.core.db.TableDesc;
import org.beetl.sql.ext.DebugInterceptor;
import org.beetl.sql.ext.gen.GenConfig;
import org.beetl.sql.ext.gen.MapperCodeGen;

public class toGenerate {



    public static void main(String[] args) throws Exception {

         String driver = "com.mysql.jdbc.Driver";
         String url="jdbc:mysql://120.26.224.193:3306/djt-admin?useUnicode=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true";
        String userName="root";
         String password="@Dajianhui2017.com";
        ConnectionSource source = ConnectionSourceHelper.getSimple(driver, url, userName, password);
        DBStyle mysql = new MySqlStyle();
// sql语句放在classpagth的/sql 目录下
        SQLLoader loader = new ClasspathLoader("/sql");
// 数据库命名跟java命名一样，所以采用DefaultNameConversion，还有一个是UnderlinedNameConversion，下划线风格的，
        UnderlinedNameConversion nc = new  UnderlinedNameConversion();
// 最后，创建一个SQLManager,DebugInterceptor 不是必须的，但可以通过它查看sql执行情况
        SQLManager sqlManager = new SQLManager(mysql,loader,source,nc,new Interceptor[]{new DebugInterceptor()});



//sql.genPojoCodeToConsole("userRole"); 快速生成，显示到控制台
// 或者直接生成java文件
        GenConfig config = new GenConfig();
//        config.preferBigDecimal(true);
//        config.setBaseClass("com.test.login");
//        sqlManager.genPojoCode("login_log","com.test",config);

        MapperCodeGen mapper = new MapperCodeGen("com.dao");
        config.codeGens.add(mapper);
        TableDesc tableDesc=new TableDesc("asd","asd");
        mapper.genCode("com.ddd","role",tableDesc,config,false);
       // sqlManager.genPojoCode("login_log", "com.aaa.aaa");
        sqlManager.genPojoCode("resource","axc");
        sqlManager.genSQLFile("role",null);
    }
}
